package com.itheima.create;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author Anomaly
 * @date 2023/2/10 14:40
 */
public class CallableDemo {
    public static void main(String[] args) {
        Callable<String> myCallable = new MyCallable();
        FutureTask<String> ft = new FutureTask(myCallable);
        new Thread(ft).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("主线程执行输出：" + i);
        }
        try {
            System.err.println(ft.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyCallable implements Callable<String> {

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 1000; i++) {
            System.out.println("子线程执行输出：" + i);
        }
        return "子线程执行完毕";
    }
}
